package org.course.weather.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class WeatherBean {
    @NotNull(message = "城市编号不能为空")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    public Integer id; // 城市编号

    @NotBlank(message = "城市名称不能为空")
    private String city; // 地域

    @NotBlank(message = "天气现象不能为空")
    private String weather; // 天气现象

    @NotBlank(message = "风向不能为空")
    @JsonProperty("wind_dir") // 保持 JSON 序列化名称
    private String wind_dir; // 风向

    @NotBlank(message = "风力不能为空")
    @JsonProperty("wind_class") // 保持 JSON 序列化名称
    private String wind_class; // 风力

    @NotNull(message = "温度不能为空")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Integer temp; // 温度

    @NotNull(message = "数据更新时间不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonProperty("update_time") // 保持 JSON 序列化名称
    private LocalDateTime update_time; // 数据更新时间

    /**
     * 无参构造函数
     */
    public WeatherBean() {
        this.update_time = LocalDateTime.now();
    }

    /**
     * 有参构造函数
     */
    public WeatherBean(Integer id, String city, String weather, String wind_dir, String wind_class, Integer temp, LocalDateTime update_time) {
        this.id = id;
        this.city = city;
        this.weather = weather;
        this.wind_dir = wind_dir;
        this.wind_class = wind_class;
        this.temp = temp;
        this.update_time = update_time;
    }

    public WeatherBean(Integer id, String city, String weather, String wind_dir, String wind_class, Integer temp) {
        this(id, city, weather, wind_dir, wind_class, temp, LocalDateTime.now());
    }
}
